﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AMPLibrary.Windows
{
    public static class ScreenSaver
    {
        private const int WM_SYSCOMMAND = 0x112;

        private const int SC_SCREENSAVE = 0xF140;

        private const int SC_MONITORPOWER = 0xF170;

        /// <summary>
        /// http://www.pixvillage.com/blogs/devblog/archive/2007/02/27/6493.aspx
        /// 
        /// August 09 2009
        /// </summary>
        /// <param name="hwnd"></param>
        /// <param name="msg"></param>
        /// <param name="wParam"></param>
        /// <param name="lParam"></param>
        /// <param name="handled"></param>
        /// <returns></returns>
        public static IntPtr DisableScreenSaverHook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            if (msg == WM_SYSCOMMAND && ((((long)wParam & 0xFFF0) == SC_SCREENSAVE) || ((long)wParam & 0xFFF0) == SC_MONITORPOWER))
                handled = true;

            return IntPtr.Zero;
        }
    }
}
